<?php

namespace app\model;

use think\Model;

class UserCar extends Model
{
    public function getPage(): array
    {
        $param = request()->param();
        $page = $param['page'] ?? 1;
        $limit = $param['limit'] ?? 50;
        $data = $this->when(!empty($param['uid']), function ($query) use ($param) {
            $query->where('uid', $param['uid']);
        })->where(['is_del' => 1])->order(['create_time' => 'desc'])->paginate(['list_rows' => $limit, 'page' => $page])->toArray();
        return ['lst' => $data['data'], 'total' => $data['total'], 'last_page' => $data['last_page']];
    }

    public function deleteCar(): array
    {
        $id = request()->param("id");
        $this->where(['id' => $id])->update(['is_del' => 0]);
        return $this->toArray();
    }

    public function addCar(): array
    {
        $param = request()->param();
        $this->save($param);
        return $this->toArray();
    }
}
